package captcha

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	resp "study/server/model/response"
	"study/server/utils/captcha"
)

type CaptchaApi struct {
}

func (c *CaptchaApi) GenerateCaptcha(ctx *gin.Context) {
	id, b64s, _, err := captcha.GenerateCaptcha()
	if err != nil {
		logrus.Error("验证码生成失败", err)
		resp.FailWithMsg("验证码生成失败", ctx)
		return
	}
	resp.OkWithData(resp.CaptchaResp{
		CaptchaID:     id,
		CaptchaBase64: b64s,
	}, ctx)
}
